/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Web Feeds is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

import QtQuick 1.1
import com.nokia.meego 1.0
import WebFeeds 1.0
import Qt.labs.gestures 1.0
import "../../shared/qml/UIConstants.js" as UIConstants
import "../../shared/qml" as Shared

PageStackWindow {
    id: appWindow
    showStatusBar: !emptyItem.visible
    property bool accountExists: appWindow.authenticatedServiceExists(webFeedsApp.services);

    function authenticatedServiceExists(serviceList) {
        for(var i = 0; i < serviceList.length; ++i) {
            if(serviceList[i].isAuthenticationDataSet())
                return true;
        }
        return false;
    }

    Component.onCompleted: {
        appWindow.pageStack.push(Qt.createComponent("MainPage.qml"), {rootItem: webFeedsApp.rootItem()})
    }   

    Item {
        id: emptyItem
        anchors.fill: parent

        visible: !appWindow.accountExists

        Shared.AddServiceDialog {
            id: addServiceDialog
        }

        Image {
            id: backgrounImage
            anchors.fill: parent
            source: appWindow.inPortrait ? "qrc:/app/emptystate-background-portrait.png"
                                         : "qrc:/app/emptystate-background-landscape.png"
        }
        Label {
            id: emptyText
            anchors.top: parent.top
            anchors.bottom: button.top
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.leftMargin: UIConstants.DEFAULT_MARGIN
            anchors.rightMargin: UIConstants.DEFAULT_MARGIN
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            wrapMode: Text.Wrap
            font.family: UIConstants.FONT_FAMILY_LIGHT
            font.pixelSize: UIConstants.FONT_XXXLARGE
            color: UIConstants.COLOR_SECONDARY_FOREGROUND
            text: qsTr("Connect to your favorite feed aggregator services")
        }
        Shared.Button {
            id: button
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 100
            text: qsTr("Add account")
            Component.onCompleted: {
                button.platformStyle.inverted = true;
            }
            onClicked: addServiceDialog.open();
        }
    }
}
